//
//  YYChildTopicTableViewCell.swift
//  STMusic
//
//  Created by stoneobs on 17/4/7.
//  Copyright © 2017年 stoneobs. All rights reserved.
//

import UIKit
let YYChildTopicTableViewCellHeight:CGFloat = 130

class YYChildTopicTableViewCell: UITableViewCell {

    var backControl:UIControl?
    
    var iconImageView:UIImageView?
    
    var titleLable :STLabel?
    
    var desLable:STLabel?
    
    var playNumLable:STLabel?
    
    var worksNumLable:STLabel?//作品
    
    var model:YYChildTopicModel = YYChildTopicModel(){
    
        didSet{
        
            self.iconImageView?.sd_setImage(with: URL.init(string: model.topic.cover_photo), placeholderImage: nil, options: .retryFailed, completed: nil);
            
            self.titleLable?.text = "#" +  model.topic.title;
            
            self.desLable?.text = model.topic.desc;
            
            self.playNumLable?.text = "播放 " + String(model.topic.play_num);
            
            self.worksNumLable?.text = "作品 " + String(model.topic.works_count);
            
        
        }
    }
    
    
    var didClicCell:() ->Void = {
    
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    override  init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier);
        self.initSubViews();
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func initSubViews() -> Void {
        self.backgroundColor = YYThemeStyleManger.defultManger.gradualColor(frame: CGRect.init(x: 0, y: 0, width: SCREEN_WIDTH, height: YYChildTopicTableViewCellHeight));
        
        self.backControl = UIControl.init(frame:CGRect.init(x: 15.0, y: 0.0, width: Double(SCREEN_WIDTH - 30), height: Double(YYChildTopicTableViewCellHeight)));
        self.backControl?.layer.cornerRadius = 3;
        self.backControl?.clipsToBounds = true;
        self.backControl?.backgroundColor = .white;
        self.backControl?.addTarget(self, action: #selector(clicControlAction), for: .touchUpInside);
        self.addSubview(self.backControl!);
        
        self.iconImageView = UIImageView.init(frame: .init(x: 0, y: 0, width: 130, height: 130));
        self.iconImageView?.backgroundColor = .gray;
        self.iconImageView?.contentMode = .scaleAspectFill;
        self.iconImageView?.clipsToBounds = true;
        self.backControl?.addSubview(self.iconImageView!);
        
        let backWidth = self.backControl?.width;
        
        self.titleLable = STLabel.init(frame:.init(x: 15 + (iconImageView?.right)!, y: 20, width: backWidth! - 30 - 130, height: 15), text: "", textColor: FirstTextColor, font: 15, isSizetoFit: false, textAlignment: .left);
        self.backControl?.addSubview(self.titleLable!);
        
        self.desLable = STLabel.init(frame: CGRect.init(x: (titleLable?.left)!, y: (titleLable?.bottom)! + 10, width: (titleLable?.width)!, height: 35), text: "", textColor: ThirdTextColor, font: 14, isSizetoFit: false, textAlignment: .left);
        
        self.desLable?.numberOfLines = 0;
        self.backControl?.addSubview(self.desLable!);
        
        
        
        self.playNumLable = STLabel.init(frame: CGRect.init(x: (titleLable?.left)!, y: (desLable?.bottom)! + 20, width: 85, height: 14), text: "", textColor: ThirdTextColor, font: 13, isSizetoFit: false, textAlignment: .left);
        
        self.playNumLable?.showRightLine(12);
        self.backControl?.addSubview(self.playNumLable!);
        
        
        self.worksNumLable = STLabel.init(frame: CGRect.init(x: (playNumLable?.right)! + 5, y: (desLable?.bottom)! + 20, width: 70, height: 14), text: "", textColor: ThirdTextColor, font: 13, isSizetoFit: false, textAlignment: .left);
        
        self.backControl?.addSubview(self.worksNumLable!);
   
        
        
    }
    func clicControlAction() -> Void {
  
        self.didClicCell();
    }

}
